package com.fsc.app_news;

import java.util.ArrayList;
import java.util.List;

import com.fsc.app_bean.Content;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class VideoActivity extends Fragment implements OnItemClickListener {
	private GridView gv_video;
	private View view;
	private Content newContent;
	private List<Content> list;
	private VideoAdapter adapter;
	private WebView webView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.activity_video,container, false);
		gv_video = (GridView) view.findViewById(R.id.gv_video);
		
		webView = (WebView) view.findViewById(R.id.webView);
		list = new ArrayList<Content>();
		list.add(new Content("韩民调：朴槿惠支持率止跌 时隔8周升至两位数",R.drawable.tu2));
		list.add(new Content("韩民调：朴槿惠支持率止跌 时隔8周升至两位数",R.drawable.tu1));
		list.add(new Content("韩民调：朴槿惠支持率止跌 时隔8周升至两位数",R.drawable.tu3));
		list.add(new Content("韩民调：朴槿惠支持率止跌 时隔8周升至两位数",R.drawable.tu4));
		adapter = new VideoAdapter(getActivity());
		gv_video.setAdapter(adapter);
		
		envet();
		return view;
	}
	public void envet(){
		gv_video.setOnItemClickListener(this);
	}
	class VideoAdapter extends BaseAdapter{

		private Context context;
  		//构造函数
  		public VideoAdapter(Context context) {  
  	        this.context = context;
  	    }
		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder hodler = null; 
  	        if(convertView == null)  
  	        {  
  	        	hodler = new ViewHolder();
  	            convertView = LayoutInflater.from(context).inflate(R.layout.item_video, null); 
  	            hodler.image = (ImageView) convertView.findViewById(R.id.iv_video);
  	            hodler.content = (TextView) convertView.findViewById(R.id.tv_title);   
  	            convertView.setTag(hodler);         //表示给View添加一个格外的数据，  
  	        } else {  
  	        	hodler = (ViewHolder) convertView.getTag();//通过getTag的方法将数据取出来  
  	        } 
  	        newContent = list.get(position); 
  	        hodler.image.setImageResource(newContent.getImage());//图片 
  	        hodler.content.setText(newContent.getContent());//内容   
  	         
  	        return convertView;
		}
		
	}
	public class ViewHolder {
		private ImageView image;
		private TextView content;
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		webView.loadUrl("http://www.iqiyi.com/");
	}
}
